package com.yc.snack.dao.impl;

import com.yc.snack.dao.ITypeInfoDao;
import com.yc.snack.dao.util.DBUtil;
import com.yc.snack.entity.TypeInfo;

import java.util.List;

/**
 * @Auther: HuYang
 * @Date: 2022/11/10 - 11 - 10 - 20:03
 * @Description: com.yc.snack.dao.impl
 * @version: 1.0
 */
public class TypeInfoDaoImpl implements ITypeInfoDao {
    @Override
    public int add(TypeInfo tf) {
        DBUtil db = new DBUtil();
        String sql = "insert into goodstype values(0,?,1)";
        return db.update(sql,tf.getTname());
    }

    @Override
    public List<TypeInfo> finds() {
        DBUtil db = new DBUtil();
        String sql = "select tno,tname from goodstype where status != 0";
        return db.finds(TypeInfo.class,sql);
    }

    @Override
    public List<TypeInfo> findByPage(int page, int rows) {
        DBUtil db = new DBUtil();
        String sql = "select tno,tname,status from goodstype order by tno limit ? , ?";
        //分页查询limit<从哪一条记录开始查><要多少条记录>
        return db.finds(TypeInfo.class,sql,(page-1) * rows,rows);
    }

    @Override
    public int getTotal() {
        DBUtil db = new DBUtil();
        String sql = "select count(tno) from goodstype";
        return Integer.parseInt(db.findStr(sql));
    }
}
